<template>
  <single-upload v-if="typeof value === 'string'"
    :width="width"
    :height="height" 
    :url="url"
    :imgsrc="value"
    :type="type"
    :isType="isType"
    :disabled="disabled" 
    @on-upload="onUploadSuccess">
  </single-upload>
  <multi-upload v-else
    :formid="formid"
    :width="width"
    :height="height" 
    :url="url"
    :imgsrc="value"
    :type="type"
    :isType="isType"
    :disabled="disabled" 
    :max="max"
    @on-upload="onUploadSuccess">
  </multi-upload>
</template>

<script>
  import SingleUpload from './singleUpload'
  import MultiUpload from './multiUpload'
  import { imgUploadUrl } from 'js/config'

  export default {
    props: {
      value: [String, Array], // img路径
      width: [Number],
      height: [Number],
      disabled: [Boolean],
      formid: '', // form表单的id
      isType: {
        type: Boolean,
        default: true
      },
      type: {
        type: String,
        default: ''
      },
      // 最多上传张数
      max: {
        type: Number,
        default: 5
      }
    },
    data() {
      return {
        url: imgUploadUrl
      }
    },
    updated() {
      this.$children[0].imageSrc = this.value
    },
    methods: {
      onUploadSuccess(src) {
        this.$emit('input', src)
      }
    },
    components: {
      SingleUpload,
      MultiUpload
    }
  }
</script>

<style lang="scss" scoped>
</style>
